package com.bwie.controller;

import cn.hutool.poi.excel.ExcelUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.bwie.poi.Excels;
import com.bwie.pojo.Attachment;
import com.bwie.pojo.Contract;
import com.bwie.service.AttachmentService;
import com.bwie.service.ContractService;
import com.bwie.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @Author: Mikey
 * @Date: 2025/9/9 12:50
 * @Description:
 **/
@RestController
@RequestMapping("shop/index")
public class ContractController {

    @Autowired
    private ContractService contractService;

    @Autowired
    private AttachmentService attachmentService;



    /***
     * @author: 秋晚
     * @description:添加合同
     * @params: [com.bwie.pojo.Contract]
     * @return: com.bwie.utils.R
     * @date: 2025/9/9 13:04
     */
    @PostMapping("saveContract")
    public R saveContract(@RequestBody @Validated Contract contract){
        return contractService.saveContract(contract);
    }

    /***
     * @author: 秋晚
     * @description:根据商铺id查询旗下合同
     * @params: [java.lang.Integer]
     * @return: com.bwie.utils.R
     * @date: 2025/9/9 14:34
     */
    @GetMapping("getContractByShopId/{shopId}/{categoryId}")
    public R getContractByShopId(@PathVariable(name = "shopId") String shopId,
                                 @PathVariable(name = "categoryId")String categoryId){
        return contractService.getContractByShopId(shopId,categoryId);
    }


    /***
     * @author: 秋晚
     * @description:根据合同id查询附件
     * @params: [java.lang.Integer]
     * @return: com.bwie.utils.R
     * @date: 2025/9/9 17:10
     */
    @GetMapping("getAttachmentById/{contractId}")
    public R getAttachmentById(@PathVariable(name = "contractId") Integer contractId){
        return R.OK(attachmentService.list(new LambdaQueryWrapper<Attachment>().eq(Attachment::getContractId,contractId)));
    }


    /***
     * @author: 秋晚
     * @description:根据id通过审核
     * @params: [java.lang.Integer]
     * @return: com.bwie.utils.R
     * @date: 2025/9/9 17:22
     */
    @PostMapping("passStatus/{id}")
    public R passStatus(@PathVariable(name = "id")Integer id){
        return contractService.passStatus(id);
    }

    /***
     * @author: 秋晚
     * @description:根据id拒绝审核
     * @params: [java.lang.Integer]
     * @return: com.bwie.utils.R
     * @date: 2025/9/9 17:22
     */
    @PostMapping("NopassStatus/{id}")
    public R NopassStatus(@PathVariable(name = "id")Integer id){
        return contractService.NopassStatus(id);
    }


//    /***
//     * @author: 秋晚
//     * @description:导出合同
//     * @params: []
//     * @return: com.bwie.utils.R
//     * @date: 2025/9/9 17:47
//     */
//    @PostMapping("exportExcel")
//    public R exportExcel(){
//
//    }
}
